package edu.neusoft.yuejian_09.activity;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.MediaController;

import java.util.List;

import edu.neusoft.yuejian_09.R;
import edu.neusoft.yuejian_09.adapter.ClubVideoAdapter;
import edu.neusoft.yuejian_09.bean.Video;
import edu.neusoft.yuejian_09.model.ClubModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class ClubVideoActivity extends Activity  {
    private ImageView left;
    private RecyclerView recyclerView;
    private ClubVideoAdapter adapter;
    private MediaController mediaController;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_club_video);
        initView();
        initEvent();
        getVideos();

    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.club_video);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局
        left = (ImageView) findViewById(R.id.left);

    }

    private void initEvent() {
        //返回上一页
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();}
        });

    }
    private void getVideos(){
        ClubModel userModel = new ClubModel();
        //发送请求
        Call<List<Video>> call = userModel.getVideos();
        //2.处理结果
        call.enqueue(new Callback<List<Video>>() {
            @Override
            public void onResponse(Call<List<Video>> call, Response<List<Video>> response) {
                List<Video> data = (List<Video>) response.body();  //获取数据
                recyclerView.setAdapter(new ClubVideoAdapter(ClubVideoActivity.this, data));
            }

            @Override
            public void onFailure(Call<List<Video>> call, Throwable t) {

            }

        });

    }


}
